<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Document</title>
    <link rel="stylesheet" href="../../css/api.css">
    <link rel="stylesheet" href="../../css/news.css">
    <link rel="stylesheet" href="../../css/login.css">
    <style>
        .login-bg {
            padding: 10px 0;
            width: 100vw;
        }
    </style>
</head>

<body>
    <div class="login-bg" id="view" v-cloak>
        <div class="wrap">
            <ul class="input-wrap w-bg">
                <li class="li phone">
                    <span class="name">登录账号</span>
                    <input type="text" placeholder="请输入手机号/账号">
                </li>
                <li class="li pwd">
                    <span class="name">登录密码</span>
                    <input type="password" placeholder="请输入密码">
                    <span class="new-theme-color forget" tapmode onclick="_url({url:'user/pwd', title:'重置密码'})">忘记密码?</span>
                </li>
            </ul>
            <button class="new-btn" tapmode onclick="submit()">登录</button>
        </div>
    </div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/jquery.js"></script>
<script src="../../script/ffkj.js"></script>
<script src="../../script/login.js"></script>
<script src="../../script/keyboard.js"></script>
<script src="../../script/vue.js"></script>

<script>
    var view = new Vue({
        el: '#view',
        data: {
            ios: 1, // 1上架 0非上架
        }
    })
    apiready = function() {
        view.ios = $api.getStorage('shang');
    }

    // 登录
    function submit() {
        var phone = $.trim($('.phone input').val());
        var pwd = $.trim($('.pwd input').val());
        if (!checkMobile(phone)) {
            _msg('请输入正确的手机号');
            return;
        }
        if (!(pwd && pwd.length >= 6)) {
            _msg('密码不能为空并且不少于6位')
            return;
        }
        if (!phone) {
            _msg('手机号未填写');
            return;
        }
        _loading();

        _ajax('api/login/index', function(ret, err) {
            if (ret && ret.code == 200) {
                _msg('登录成功');

                $api.setStorage('userid', ret.result.id);
                $api.setStorage('sex', ret.result.sex);
                loginToUpdate(ret.result.id)
                _home()
            } else if (ret && ret.code == 201) {
                _msg('该账号还没为注册');
            } else if (ret && ret.code == 202) {
                _msg('密码不正确');
            } else if (ret && ret.code == 203) {
                _msg('账号已被封禁，请联系客服');
            } else {
                _msg(ret.msg);
            }
        }, {
            phone: phone,
            password: pwd,
        })
    }
</script>

</html>